<#assign tit>设置权限</#assign>
<@page.html title=tit>
<style>
  table.list tr.pt th {height:23px;}
  table.list tr.pt td {background-color:#f0f4ff;}
  table.list td.cptb {padding:0 0 0 10px;}
  td.cptb table {margin:-1px -1px -1px 1px;}
</style>
<script type="text/javascript">
  function checkNull(cc) {
    if(!cc.checked) {
      var cs = document.getElementsByName(cc.name);
      for(var i=0; i<cs.length; i++)
        cs[i].checked = false;
    } else {
      var cf1 = document.getElementById(cc.name+"_f1");
      if(cf1) cf1.checked = false;
    }
    var tr = getEl("tr_ac_"+cc.getAttribute("mid"));
    if(tr) tr.style.display = cc.checked?"":"none";
  }
  function checkFirst(cc) {
    var c0 = document.getElementById(cc.name+"_0");
    if(!c0) return;
    if(cc.checked) {
      c0.checked = true;
      var cf1 = document.getElementById(cc.name+"_f1");
      if(cf1) cf1.checked = false;
    }
    var tr = getEl("tr_ac_"+c0.getAttribute("mid"));
    if(tr) tr.style.display = c0.checked?"":"none";
  }
  function checkEnable(cc) {
    if(cc.checked) {
      var cs = document.getElementsByName(cc.name);
      for(var i=0; i<cs.length; i++)
        if(cs[i]!=cc) cs[i].checked = false;
    }
    var c0 = document.getElementById(cc.name+"_0");
    if(!c0) return;
    var tr = getEl("tr_ac_"+c0.getAttribute("mid"));
    if(tr) tr.style.display = c0.checked?"":"none";
  }
</script>
<div style="width:640px;">
  <dl class="title"><dt class="config">${tit} - ${user.chName!}(${user.userCode!})</dt></dl>

  <form id="fm_input" method="post" action="_auth" onsubmit="return post(this);">
    <input type="hidden" name="userCode" value="${user.userCode!}">
    <table class="list" id="tb_auth">
      <#if plist??><#list plist as m>
      <tr id="tr_a_${m.menuId!}"><#if m.parentId=0>
        <th class="left">${m.menuName!}</th>
        <th width="30"><input type="checkbox" name="auth_${m.menuId!}" id="auth_${m.menuId!}_0" mid="${m.menuId!}" value="1"<#if m.authority gt 0> checked</#if>></th>
        <th width="400" class="left">操作</th>
        <th width="30">禁用</th><#else>
        <td class="left">${m.menuName!}</td>
        <td width="30"><input type="checkbox" name="auth_${m.menuId!}" id="auth_${m.menuId!}_0" mid="${m.menuId!}" value="1"<#if m.authority gt 0> checked</#if> onclick="checkNull(this);"></td>
        <td width="400" class="left">${m.authHtml!}</td>
        <td width="30"><input type="checkbox" name="auth_${m.menuId!}" id="auth_${m.menuId!}_f1" value="-1"<#if m.authority lt 0> checked</#if> onclick="checkEnable(this);"></td></#if>
      </tr>
      </#list></#if>
    </table>
    <div class="button"><input type="submit" value="提 交"></div>
  </form>
</div>
<script type="text/javascript">
  var _mls = new Array();
  <#if mlist??><#list mlist as m><#if m.parentId!=0>
  _mls.push(["${m.menuId!}","${m.menuName!}","${m.parentId!}",${m.authority!},"${m.authHtml!}"]);
  </#if></#list></#if>
  function init() {
    var i, mm, tb, tr, td, bs, cc;
    for(i=0; i<_mls.length; i++) {
      mm = _mls[i];
      tb = getEl("tb_ac_"+mm[2]);
      if(tb==null) {
        tr = getEl("tr_a_"+mm[2]);
        if(!tr) continue;
        tr.className = "pt";
        tr = tr.parentNode.insertRow(tr.rowIndex+1);
        tr.id = "tr_ac_"+mm[2];
        bs = false;
        cc = getEl("auth_"+mm[2]+"_0");
        if(cc && cc.checked) bs = true;
        if(!bs) tr.style.display = "none";
        td = tr.insertCell(-1);
        td.colSpan = "4";
        td.className = "cptb";
        td.innerHTML = '<table class="list" id="tb_ac_'+mm[2]+'"></table>';
        tb = getEl("tb_ac_"+mm[2]);
      }
      if(tb==null) continue;
      tr = tb.insertRow(-1);
      tr.id = "tr_a_"+mm[0];
      td = tr.insertCell(-1);
      td.className = "left";
      td.innerHTML = mm[1];
      td = tr.insertCell(-1);
      td.width = "30";
      td.innerHTML = '<input type="checkbox" name="auth_'+mm[0]+'" id="auth_'+mm[0]+'_0" mid="'+mm[0]+'" value="1"'+(mm[3]>0?' checked':'')+' onclick="checkNull(this);">';
      td = tr.insertCell(-1);
      td.width = "400";
      td.className = "left";
      td.innerHTML = mm[4];
      td = tr.insertCell(-1);
      td.width = "30";
      td.innerHTML = '<input type="checkbox" name="auth_'+mm[0]+'" id="auth_'+mm[0]+'_f1" value="-1"'+(mm[3]<0?' checked':'')+' onclick="checkEnable(this);">';
    }
  }
  init();
</script>
</@page.html>